<?php
Zend_Session::start();

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initAutoload(){

		$modelLoader = new Zend_Application_Module_Autoloader(
			array(
				'namespace' => '',
				'basePath' => APPLICATION_PATH
			)
		);
		//Auteticacion, se hace antes de cualquier evento basado en plugin AccessCheck
		$acl = new Model_LibraryAcl;
		$auth = Zend_Auth::getInstance();
		$fc = Zend_Controller_Front::getInstance();

		$fc->registerPlugin(new Plugin_AccessCheck($acl,$auth));
		return $modelLoader;
	}
	/***
	 * Cargamos las vistas en base al layout
	*/

	function _initViewHelpers()
	{
		include(APPLICATION_PATH."/plugins/metatags.php");
		
		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		$view = $layout->getView();

		$view->doctype('XHTML1_TRANSITIONAL');
		//$view->doctype('HTML4_STRICT');
		$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html; charset=utf-8');

		//<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
		$view->headTitle()->setSeparator(' - ');
		$view->headTitle('Rock alterno');

		$s_Sass = new Zend_Session_Namespace('s_Sass');
		$view->user_name 	= $s_Sass->UserName;

	}
	/**
	 * Plugin para usar varios idiomas
	 */
	function _initSetTranslations(){

		$this->bootstrap('layout');
		$layout = $this->getResource('layout');
		$view = $layout->getView();

		$translate = @new Zend_Translate('gettext',
		APPLICATION_PATH.'/languages',
		null,
		array('scan' => Zend_Translate::LOCALE_FILENAME)
		);

		Zend_Validate_Abstract::setDefaultTranslator($translate);

		$session = new Zend_Session_Namespace('s_Sass');
		$locale = new  Zend_Locale();

		if(isset($session->language)){
			$requestedLanguage = $session->language;
			$locale->setLocale($requestedLanguage);
		}else{
			$locale->setLocale(Zend_Locale::BROWSER);
			$requestedLanguage = key($locale->getBrowser());
		}

		if(in_array($requestedLanguage, $translate->getList())){
			$language = $requestedLanguage;
		}else {
			$language = 'es';
		}

		Zend_Registry::set('locale', $locale);
		$translate->setLocale($language);

		$view->translate = $translate;
		$session->language=$language;

		Zend_Registry::set('Zend_Translate', $translate);
	}

	/**
	 * Plugin para usar varios layouts
	 */
	protected function _initPlugins(){
		include(APPLICATION_PATH."/plugins/Layout.php");

		$this->bootstrap('frontController');
		$plugin = new Layout();
		$this->frontController->registerPlugin($plugin);
	}

}
